package taskMgr;

import defaultPackage.Grid;
import defaultPackage.Person;
import defaultPackage.tileType;

import java.awt.*;

import pathfind.Path;
import pathfind.PathFinder;

public abstract class Task 
{
	int numPeople = 0;
	
	private static long nextid = 0;
	private long id;
	private Person person;
	private TaskStatus status = TaskStatus.waiting; 
	public int x,y,progress = 0;
	boolean isBuildTile = false;
	public Task()
	{
		id=nextid;
		nextid++;
	}
	public long getid()
	{
		return id;
	}
	public TaskStatus getStatus()
	{
		return status;
	}
	public void setStatus(TaskStatus stat)
	{
		status=stat;
	}
	public abstract void action(Person p);
	public abstract void draw(Graphics g);
	public abstract void performTask(Person p);
	
	public boolean canReachTask(Person p)
	{
		p.map.clean();
		PathFinder f = new PathFinder(p.map);
		f.start(p.getX(), p.getY());
		f.run();
		Path test = new Path(p.map, x, y);
		return test.getList().size() > 0;
	}
	
	public void setBuildTile(boolean a)
	{
		this.isBuildTile = a;
	}
	
	public boolean isBuildTile()
	{
		return isBuildTile;
	}
	public void setNumPeople(int p)
	{
		this.numPeople = p;
	}
	
	public int getNumPeople()
	{
		return numPeople;
	}
	
	public int getNumJobs(Manager manager)
	{
		int numJobs = 0;
		for (Task t:manager.taskList)
		{
			if (Math.abs(t.x - x) <= 1 && Math.abs(t.y - y) <= 1)
			{
				numJobs++;
			}
		}
		return numJobs;
	}
}
